class AuthController < ApplicationController
  def login
    #@user = User.new

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @user }
    end
  end

  def logout
    #cookies.delete :riskfit_token
    session[:user_id] = nil
    redirect_to login_url
  end
  
  def try_to_login
    #@user = User.new
    name = params[:user][:name]
    password = params[:user][:pwd]    
    login_user = User.try_to_login(name,password)
    #if params[:auto]
    #Cookieauto.create(name, pwd_salt)
    #cookies[:riskfit_token]={:value=>pwd_salt,:expires => Time.now + 7.days}
    #end
    respond_to do |format|
      if !login_user.nil?
        #@current_user = login_user
        session[:user_id] = login_user.id
        format.html { redirect_to welcome_url }
        format.json { head :no_content }
      else        
        format.html { redirect_to login_url , notice: "login failed" }
        format.json { head :no_content }
        #format.json { render json: @user.errors, notice: "login failed" }
      end
    end
  end
end
